﻿using Sharp.Framework.Logger;
//using MySql.Data.MySqlClient;
using System.Text;

namespace Sharp.Framework.Email
{
    public interface ISmsUnity
    { 
        /// <summary>
        /// 系统邮件立即发送
        /// </summary>
        /// <param name="command"></param>
        bool Send(string[] revicers,string content);
    }

    public class SmsUnityUnity : ISmsUnity
    {
        /// <summary>
        /// 系统邮件立即发送
        /// </summary>
        /// <param name="command"></param>
        public bool Send(string[] revicers, string content)
        {
            //content = GB2312ToUTF8(content);
            //var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlStr"].ConnectionString;
            //var commandText = "INSERT INTO api_mt_222(content,mobiles) values (?content,?mobiles)"; 
            //using (MySqlConnection connection = new MySqlConnection(connectionString))
            //{
            //    using (MySqlCommand cmd = new MySqlCommand(commandText,connection))
            //    {
            //        try
            //        { 
            //            connection.Open(); 
            //            cmd.Parameters.Add("?mobiles", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = string.Join(",", revicers);
            //            cmd.Parameters.Add("?content", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = content;
            //            cmd.ExecuteNonQuery();
            //        }
            //        catch (MySqlException e)
            //        { 
            //            Log.Error(e, string.Format("发送短信失败,接收号码:{0};连接字符串:{1};内容:{2}", string.Join(",", revicers),connectionString, content));

            //            return false;
            //        }
            //        finally
            //        {
            //            cmd.Dispose();
            //            connection.Close();
            //        }
            //    }
            //}
            return true;
        }
        string GB2312ToUTF8(string gbstr)
        {
            var gb2312 = Encoding.GetEncoding("gb2312");
            var utf8 = Encoding.UTF8;
            byte[] bs = Encoding.Convert(gb2312, utf8, gb2312.GetBytes(gbstr));
            return utf8.GetString(bs);
        }
    }


    public interface IFaxUnity
    {
        /// <summary>
        /// 系统邮件立即发送
        /// </summary>
        /// <param name="command"></param>
        bool Send(string[] revicers, string content);
    }

    public class FaxUnityUnity : IFaxUnity
    {
        /// <summary>
        /// 系统邮件立即发送
        /// </summary>
        /// <param name="command"></param>
        public bool Send(string[] revicers, string content)
        {
            Log.Debug(string.Format("发送传真成功,接收号码:{0};内容:{1}", string.Join(",", revicers), content));
            return true;
        }
    }
}